Skip to content

Don't derive an HMAC key from an empty client secret - #579

Merged
maennchen merged 2 commits into
erlef:mainfrom
ardraayyappath:harden/reject-empty-client-secret
Nov 18, 2026
Merged

maennchen merged 2 commits into
erlef:mainfrom
ardraayyappath:harden/reject-empty-client-secret

Conversation

@ardraayyappath

@ardraayyappath ardraayyappath commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

oidcc_jwt_util:client_secret_oct_keys/2 builds an oct JWK from the client secret whenever an HS* algorithm
is allowed. It only skips the unauthenticated atom, so a client context built with client_secret = <<>>
(for example from an unset environment variable) gets a zero-length HMAC key. That key then joins the
verification key set for ID tokens, JARM responses and signed userinfo, and the signing/encryption key set
for request objects.

An empty secret is never a working configuration, so this PR stops it in two places:

  1. At startup. oidcc_client_context:from_configuration_worker/3,4 return {error, empty_client_secret},
    and from_manual/4,5 raise empty_client_secret. Public clients should use unauthenticated.
  2. At key derivation. <<>> is treated like unauthenticated, so HS*-signed content fails with
    no_matching_key even if a context with an empty secret is built some other way.

Clients configured correctly are unaffected.

Changes:

  • src/oidcc_jwt_util.erl: new client_secret_oct_keys(_, <<>>) -> none clause.
  • src/oidcc_client_context.erl, lib/oidcc/client_context.ex: reject <<>> in the constructors; docs
    updated; empty_client_secret added to oidcc_client_context:error().
  • Tests:
    • test/oidcc_jwt_util_test.erl, test/oidcc_token_test.erl: the key-derivation guard, including an
      ID token and a JARM response signed with an empty key.
    • test/oidcc_client_context_test.erl, test/oidcc/client_context_test.exs: the constructors.
    • test/oidcc_authorization_test.erl: create_redirect_url_with_request_object_no_hmac_test now uses a
      dummy secret instead of <<"">>, as guides/private-key-jwt.md recommends.

Behaviour change: code passing "" as the client secret, e.g. as the #442 workaround for a
client_jwks-only client, now fails at startup. A non-empty dummy secret still works. Probably worth a
changelog note.

Testing (OTP 29 / Elixir 1.20): rebar3 fmt, eunit (152), ct (24), lint, hank and dialyzer, plus mix
format, test (81) and dialyzer, all pass.

client_secret_oct_keys/2 only skipped the unauthenticated atom, so a client
context with client_secret = <<>> produced a zero-length oct key that was
added to the verification keys for ID tokens, JARM responses and userinfo,
and to the request object keys. Treat <<>> like unauthenticated.
@maennchen

Copy link
Copy Markdown
Member

Possible follow-up (left out to keep this non-breaking; happy to add if wanted): reject <<>> up front in
oidcc_client_context:from_manual/5 / from_configuration_worker/4 so the misconfiguration surfaces at
startup.

I think that would be sensible 👍

from_configuration_worker/3,4 now return {error, empty_client_secret} and
from_manual/4,5 raise empty_client_secret, so the misconfiguration shows up
at startup instead of as failed token requests. Use unauthenticated for
public clients.

The request-object test that used <<"">> as a stand-in secret for a
client_jwks client now uses a dummy secret, as guides/private-key-jwt.md
recommends.
@ardraayyappath

Copy link
Copy Markdown
Contributor Author

Added the up-front check in f1ef337:

  • from_configuration_worker/3,4 return {error, empty_client_secret}. It's added to
    oidcc_client_context:error(), so the oidcc:* helpers return it too.
  • from_manual/4,5 raise empty_client_secret, because they return the record directly.
  • The key-derivation guard from the first commit stays as a second layer.

One thing to flag: create_redirect_url_with_request_object_no_hmac_test used <<"">> as the stand-in
secret for a client_jwks-only client, i.e. the #442 workaround. I switched it to a dummy secret, as
guides/private-key-jwt.md already recommends, and it still passes. But anyone using "" for that
workaround will now get an error at startup, so a changelog note is probably worth it. Happy to change the
error shape (e.g. badarg) if you prefer.

I've updated the PR description to match.

@maennchen

Copy link
Copy Markdown
Member

I should rethink that API at some point. Dummy values is not exactly a good way to do this.

@maennchen
maennchen merged commit f4114ce into erlef:main Nov 18, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants